package com.homegoods.shoppingcar.item;

import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.shoppingcar.R;
import com.homegoods.shoppingcar.model.ShoppingCartBean;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.BaseItem;

/**
 * @author QiQi
 * @ClassName: ShoppingCartItem
 * @date 2018/10/11
 * @description 购物车- 店铺数据
 */
public class ShoppingCartItem extends BaseItem<ShoppingCartBean> {
    public ShoppingCartItem(ShoppingCartBean data, MultiTypeAdapter adapter) {
        super(data);
        setOnClickListener(v -> {
            if (v.getId() == R.id.ll_shop_name) {
                //查看店铺详情
                ARouter.getInstance()
                        .build(ARouterPath.PATH_SHOP_DETAIL)
                        .navigation();
            } else if (v.getId() == R.id.shopping_group_check) {
                //店铺全选
                toggle();
                v.setTag(data.getGroupItemPosition());
                if (adapter.getOnItemClickListener() != null) {
                    adapter.getOnItemClickListener().onItemClicked(v, this);
                }
            }
        });
    }

    private void toggle() {
        getData().setIsGroupSelected(!getData().isGroupSelected());
    }

    public String getShopName() {
        return getData().getMerchantName();
    }

    public int isSelected() {
        return getData().isGroupSelected() ? R.mipmap.icon_selected : R.mipmap.icon_unselected;
    }

    @Override
    public int getLayout() {
        return R.layout.shopping_item_shop;
    }
}
